Skip to content

feat(web): add static file serving via process_request hook#109

Merged
kimit0310 merged 2 commits into
devfrom
feature/serve-static-and-server-orchestration-entry
Apr 13, 2026
Merged

feat(web): add static file serving via process_request hook#109
kimit0310 merged 2 commits into
devfrom
feature/serve-static-and-server-orchestration-entry

Conversation

@kimit0310
Copy link
Copy Markdown
Collaborator

Adds static file serving to the WebSocket server so the upcoming SvelteKit frontend can be served from the same port.

The websockets library has a process_request hook that fires before every WebSocket handshake. We use it to check whether the incoming request is a regular HTTP request (no Upgrade header) and if so, serve the file from web/static/. WebSocket connections pass through to ws_handler as before.

Path traversal is handled by resolving the requested path and checking it stays inside STATIC_DIR via Path.relative_to(). Percent encoded characters are decoded first so tricks like %2e%2e don't bypass the check.

New helper functions _is_websocket_upgrade, _serve_static_file, _is_within_static_dir, _error_response added.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@1d3cf2e). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev     #109   +/-   ##
======================================
  Coverage       ?   90.46%           
======================================
  Files          ?        8           
  Lines          ?      304           
  Branches       ?        0           
======================================
  Hits           ?      275           
  Misses         ?       29           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimit0310 kimit0310 marked this pull request as ready for review April 1, 2026 15:39
@kimit0310 kimit0310 requested a review from Asanto32 April 1, 2026 15:39
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments + import issues

Comment thread src/MoBI_View/web/server.py Outdated
Comment thread src/MoBI_View/web/server.py Outdated
Comment thread src/MoBI_View/web/server.py Outdated
Comment thread src/MoBI_View/web/server.py Outdated
Comment thread src/MoBI_View/web/server.py
Comment thread tests/unit/test_server.py Outdated
Comment thread tests/unit/test_server.py
Comment thread tests/unit/test_server.py Outdated
Comment thread tests/unit/test_server.py Outdated
@Asanto32
Copy link
Copy Markdown
Collaborator

Asanto32 commented Apr 8, 2026

lgtm

@kimit0310 kimit0310 merged commit 9b8771f into dev Apr 13, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants